package multidraw.tools;

import java.awt.Point;
import java.awt.event.MouseEvent;

import multidraw.model.DrawingCanvasModel;
import multidraw.model.Shape;
import multidraw.model.TwoEndBoundaryShape;
import multidraw.model.TwoEndShape;



public class TwoEndShapeTool extends Tool {
	protected DrawingCanvasModel myModel;
	protected Point startingMousePosition;
	protected Point currentMousePosition;
	protected TwoEndShape shape;
	protected TwoEndShapeFactory factory;
	
	public TwoEndShapeTool(DrawingCanvasModel myModel, TwoEndShapeFactory factory) {
		this.myModel = myModel;
		this.factory = factory;
	}

	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		//create new temp shape
		shape = factory.createShape(e.getPoint(), e.getPoint(), myModel.getPenColor());
		startingMousePosition = e.getPoint();
		currentMousePosition = e.getPoint();
		//update content
		myModel.notifyObservers();
	}

	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		//add shape to the model and return to the normal state
		myModel.addShape((Shape)shape);
		shape = null;
		//notify observers
		myModel.notifyObservers();
		
	}

	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	//Mouse motion listener's methods
	
	public void mouseDragged(MouseEvent e) {
		// TODO Auto-generated method stub
		//update the shape information,
		//then update the model
		currentMousePosition = e.getPoint();
		if (shape != null) {
			shape.updateShapeInfo(startingMousePosition, currentMousePosition);
		}
		
		//update model's views
		myModel.notifyObservers();
	}

	public void mouseMoved(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	
	public Shape getShape() {
		return (Shape)shape;
	}
	
}
